﻿using AutoDeployForSims.Entity;
using AutoDeployForSims.Service;
using AutoDeployForSims.Utility;
using MyUtility.Utility;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoDeployForSims.ViewModel
{
    public class CANTotalInfoControlViewModel : ViewModelBase
    {
        private GetConfigService getConfigService = SingletonProvider<GetConfigService>.Instance;
        List<CANTotalInfoEntity> cANTotalInfos = new List<CANTotalInfoEntity>();
        List<FrankCFGInfoEntity> frankCFGInfos = new List<FrankCFGInfoEntity>();
        #region ViewModel

        private ObservableCollection<CANInfoControlViewModel> cANTabs = new ObservableCollection<CANInfoControlViewModel>();

        public ObservableCollection<CANInfoControlViewModel> CANTabs
        {
            get { return cANTabs; }
            set
            {
                cANTabs = value;
                RaisePropertyChanged("CANTabs");
            }
        }


        #endregion

        public CANTotalInfoControlViewModel()
        {
            Initial();
        }

        private void Initial()
        {
            if (getConfigService.ReadFrankConfig(ref frankCFGInfos))
            {
                if (getConfigService.ReadAnalogCanConfig(frankCFGInfos, ref cANTotalInfos))
                {
                    int num = cANTotalInfos.Count;
                    CANTabs.Clear();
                    for (int i = 0; i < num; i++)
                    {
                        CANInfoControlViewModel CANInfoControlVM = new CANInfoControlViewModel(cANTotalInfos[i]);
                        CANInfoControlVM.CANTotalInfoEnt.Title = cANTotalInfos[i].Title;
                        CANInfoControlVM.CANTotalInfoEnt.CommIP = cANTotalInfos[i].CommIP;
                        CANInfoControlVM.CANTotalInfoEnt.CommPort = cANTotalInfos[i].CommPort;
                        CANInfoControlVM.CANTotalInfoEnt.CANAddress = cANTotalInfos[i].CANAddress;
                        CANInfoControlVM.CANTotalInfoEnt.MoudleId = cANTotalInfos[i].MoudleId;
                        CANInfoControlVM.CANTotalInfoEnt.MoudleNameList = cANTotalInfos[i].MoudleNameList;
                        ToolTypeNames toolTypeName = ToolTypeNames.type_Unknow;
                        CANInfoControlVM.CANTotalInfoEnt.ToolTypeName = toolTypeName;
                        CANTabs.Add(CANInfoControlVM);
                    }

                }
            }
                
        }


    }
}
